package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.utils.poi.ExcelUtilJyjc;
import com.ruoyi.system.domain.JyjcSharingExpensesSum;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JyjcImportLbys;
import com.ruoyi.system.service.IJyjcImportLbysService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 六部一所导入Controller
 * 
 * @author ruoyi
 * @date 2025-08-08
 */
@RestController
@RequestMapping("/system/JyjcImportLbys")
public class JyjcImportLbysController extends BaseController
{
    @Autowired
    private IJyjcImportLbysService jyjcImportLbysService;

    /**
     * 查询六部一所导入列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(JyjcImportLbys jyjcImportLbys)
    {
        startPage();
        List<JyjcImportLbys> list = jyjcImportLbysService.selectJyjcImportLbysList(jyjcImportLbys);
        return getDataTable(list);
    }

    /**
     * 导出六部一所导入列表
     */
    @Anonymous
    @Log(title = "六部一所导入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JyjcImportLbys jyjcImportLbys)
    {
        List<JyjcImportLbys> list = jyjcImportLbysService.selectJyjcImportLbysList(jyjcImportLbys);
        ExcelUtil<JyjcImportLbys> util = new ExcelUtil<JyjcImportLbys>(JyjcImportLbys.class);
        util.exportExcel(response, list, "六部一所导入数据");
    }

    /**
     * 获取六部一所导入详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jyjcImportLbysService.selectJyjcImportLbysById(id));
    }

    /**
     * 新增六部一所导入
     */
    @Anonymous
    @Log(title = "六部一所导入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JyjcImportLbys jyjcImportLbys)
    {
        return toAjax(jyjcImportLbysService.insertJyjcImportLbys(jyjcImportLbys));
    }

    /**
     * 修改六部一所导入
     */
    @Anonymous
    @Log(title = "六部一所导入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JyjcImportLbys jyjcImportLbys)
    {
        return toAjax(jyjcImportLbysService.updateJyjcImportLbys(jyjcImportLbys));
    }

    /**
     * 删除六部一所导入
     */
    @Anonymous
    @Log(title = "六部一所导入", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jyjcImportLbysService.deleteJyjcImportLbysByIds(ids));
    }
    @Anonymous
    @Log(title = "收支汇总", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, String yearyf) throws Exception
    {
        ExcelUtilJyjc<JyjcImportLbys> util = new ExcelUtilJyjc<JyjcImportLbys>(JyjcImportLbys.class);
        List<JyjcImportLbys> jyjcSharingExpensesSumList = util.importExcel(file.getInputStream(),4);

        String message = jyjcImportLbysService.importJyjcImportLbys(jyjcSharingExpensesSumList, yearyf);
        return success(message);
    }
    @Anonymous
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<JyjcImportLbys> util = new ExcelUtil<JyjcImportLbys>(JyjcImportLbys.class);
        util.importTemplateExcel(response, "收支汇总数据");
    }
}
